package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.AdminAction;
import gatperdut.chato.core.interpreter.grammar.comminfo.ShutdownInfo;

public class ShutdownAction extends AdminAction {

    public ShutdownAction( ShutdownInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        AdminCheckResult acr = checkAdminUser();
        if ( !acr.isAllowed() ) {
            getEntityController().tx( acr.getMessage() );
            return CommandExecutionResult.OK;
        }

        getEntityController().getChatoServer().shutdown();

        return CommandExecutionResult.OK;
    }

    @Override
    public ShutdownInfo getInfo() {
        return (ShutdownInfo) super.getInfo();
    }
}
